package com.gpzx.zx.module.mine.ui.fragment

import android.content.Context
import android.text.TextUtils
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide

import com.gpzx.zx.databinding.ItemCollectionBinding
import com.wkq.database.dao.CollectionNewsInfo
import com.wkq.lib_base.adapter.KtDataBindingAdapter
import com.wkq.lib_base.adapter.KtDataBindingViewHolder
import com.wu.common.utils.DateTimeUtil

/**
 *
 * 作者:吴奎庆
 *
 * 时间:2020/7/17
 *
 * 用途:
 */


class CommentAdapter(context: Context, layoutId: Int) : KtDataBindingAdapter<CollectionNewsInfo>(context, layoutId) {
    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        super.onBindViewHolder(holder, position)
        var bindingHolder = holder as KtDataBindingViewHolder
        var binding = bindingHolder.viewBinding as ItemCollectionBinding
        binding.data = getItem(position)
        if (TextUtils.isEmpty(getItem(position)!!.news_icon)) {
            binding.ivIcon.visibility = View.GONE
        } else {
            Glide.with(mContext).load(getItem(position)!!.news_icon).into(binding.ivIcon)
            binding.ivIcon.visibility = View.VISIBLE
        }
        var mTime = getItem(position)!!.news_time
        if (!TextUtils.isEmpty(mTime)) {
            if (getItem(position)!!.news_time!!.toLongOrNull() == null) {
                binding.tvTime.setText(mTime)
            } else {
                var time = DateTimeUtil.formatDateTime(mTime!!.toLong())
                binding.tvTime.setText(time.toString())
            }
        }
        if (viewClickListener != null) {
            binding.root.setOnClickListener {
                viewClickListener?.onViewClick(binding.root, getItem(position))
            }

        }
    }
}